search

Home  >  Q&A  >  body text

Undefined constant 'text' in /home/jokebo/public_html/index.php:23

I have a PHP project that connects to a SQL database. The problem is that I cannot access the value of the text in the following code:

$sher = $db->query("SELECT * FROM sher1 ORDER BY RAND() LIMIT 1");
 $matn = $sher[0][text];

What went wrong? How can I fix it?

Access table values ​​in array

P粉422227023P粉422227023514 days ago774

reply all(1)I'll reply

  • P粉576184933

    P粉5761849332023-09-17 10:23:59

    Suppose there is a result (result greater than 0) and there is a "text" column. You are missing double quotes because "text" without double quotes will be recognized as a constant. Here’s how to fix it

    $sher = $db->query("SELECT * FROM sher1 ORDER BY RAND() LIMIT 1");
    $matn = $sher[0]["text"];

    reply
    0
  • Cancelreply