Jump to content


  • Content count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About shams

  • Rank
    Regular Member

Profile Information

  • Gender
  1. I search the internet to find the solution from multiple row insertion there was many codes but i cannot use for my query this is a piece of code, please help how to execute for multiple rows insertion: <?php $host = 'localhost'; $db = 'test'; $user = 'user'; $pass = ''; $charset = 'utf8mb4'; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; $pdo = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass, $options); /////// $cat_id=$_POST['cat-id']; $subcategory=$_POST['subcategory']; $subcat2=$_POST['subcat2']; $subcategory2=$_POST['subcategory2']; $sql = "INSERT INTO subcategory (cat_id, subcategory, subcat2) VALUES (?,?,?),(?,?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$cat_id, $subcategory, $subcat2],[$cat_id, $subcategory2, $subcat2]); ?>
  2. shams

    php mysql adding zero to emtpy row?

    <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "user", "", "quran"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Escape user inputs for security $cat_id = mysqli_real_escape_string($link, $_REQUEST['cat_id']); $subcategory = mysqli_real_escape_string($link, $_REQUEST['subcategory']); $subcat2 = mysqli_real_escape_string($link, $_REQUEST['subcat2']); $cat_id_2 = mysqli_real_escape_string($link, $_REQUEST['cat_id_2']); $subcategory2 = mysqli_real_escape_string($link, $_REQUEST['subcategory2']); $subcat2_2 = mysqli_real_escape_string($link, $_REQUEST['subcat2_2']); $cat_id_3 = mysqli_real_escape_string($link, $_REQUEST['cat_id_3']); $subcategory3 = mysqli_real_escape_string($link, $_REQUEST['subcategory3']); $subcat2_3 = mysqli_real_escape_string($link, $_REQUEST['subcat2_3']); $cat_id_4 = mysqli_real_escape_string($link, $_REQUEST['cat_id_4']); $subcategory4 = mysqli_real_escape_string($link, $_REQUEST['subcategory4']); $subcat2_4 = mysqli_real_escape_string($link, $_REQUEST['subcat2_4']); // attempt insert query execution $sql = "INSERT INTO subcategory (cat_id, subcategory, subcat2) VALUES ('$cat_id', '$subcategory', '$subcat2'), ('$cat_id_2', '$subcategory2', '$subcat2_2'), ('$cat_id_3', '$subcategory3', '$subcat2_3'), ('$cat_id_4', '$subcategory4', '$subcat2_4')"; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // close connection mysqli_close($link); ?>
  3. shams

    php mysql adding zero to emtpy row?

    This is the code for variable and there is no other testing code: // Escape user inputs for security $cat_id = mysqli_real_escape_string($link, $_REQUEST['cat_id']); $subcategory = mysqli_real_escape_string($link, $_REQUEST['subcategory']); $subcat2 = mysqli_real_escape_string($link, $_REQUEST['subcat2']);
  4. I created a html form to insert 4 rows in to mysql table with the one submit button and the php mysqli_query(), but some times i need to only insert one or two rows, when i want to insert two rows and run the query with the submit button, the query create two more rows with the 0 values in the first column, how to solve this problem to only insert the rows i want? this is tables attributes; mysql> DESCRIBE subcategory; +-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | cat_id | int(3) | YES | | NULL | | | subcategory | varchar(25) | YES | | NULL | | | subcat2 | varchar(25) | YES | | NULL | | +-------------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)
  5. Thanks for the hint, i remove the line $row = mysqli_fetch_assoc($result); now it work.
  6. My web pages are organized in two mysql tables, table category with two columns cat_id and category and table subcategory with three columns cat_id, subcategory and subcat2, i run this msyql query from terminal it is working: mysql> SELECT subcat2 from subcategory WHERE cat_id=1 AND subcategory=3; +--------------+ | subcat2 | +--------------+ | 001_003.html | +--------------+ 1 row in set (0.01 sec) Next, i execute the dd-mysqli.php it successfully get the sql query values from the drop down menu and parse to the chgoto.php and run this as well this is in the dd-mysqli.php: echo "<form method=post name=f1 action='chgoto.php'>"; to print the cat_id and subcategory, it is working, this is chgoto.php: <?php require 'config-mysqli.php'; //////// End of connecting to database //////// $cat=$_POST['cat']; $page=$_POST['subcat']; echo "$cat <br> $page"; ?> the reslut is shown here: 1 (is cat_id) 3 (is subcategory The problem is with the next php code, i want to add a sql query with two conditions in the chgoto.php to get the subcat2 value which is the url of html pages (as i run this mysql query in termianl in the begining of this post) but this is not working and there is only blank page in the output: <?php require 'config-mysqli.php'; //////// End of connecting to database //////// $cat=$_POST['cat']; $page=$_POST['subcat']; $result = mysqli_query($connection,'SELECT subcat2 from subcategory WHERE cat_id='.$cat.' AND subcategory='.$page.''); $row = mysqli_fetch_assoc($result); while($row = mysqli_fetch_assoc($result)){ $url = $row['subcat2']; echo $url; exit ; } $result->close(); $connection->close(); ?> I already enabled the php error log but no errors are reported for this query.
  7. shams

    Two dropdown menu in php?

    Finally the problem solved.
  8. shams

    Two dropdown menu in php?

    this is code prints the values: <?php require 'config.php'; // Database connection //////// End of connecting to database //////// ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple drop down list box from plus2net</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='dd.php?cat=' + val ; } </script> </head> <body> <?Php @$cat=$_GET['cat']; // Use this line or below line if register_global is off if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not. echo "Data Error"; exit; } ///////// Getting the data from Mysql table for first list box////////// $quer2="SELECT DISTINCT category,cat_id FROM category order by category"; ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// if(isset($cat) and strlen($cat) > 0){ $quer="SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory"; }else{$quer="SELECT DISTINCT subcategory FROM subcategory order by subcategory"; } ////////// end of query for second subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='dd-check.php'>"; /// Add your form processing page address to action in above line. Example action=dd-check.php//// ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; foreach ($dbo->query($quer2) as $noticia2) { if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";} else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='subcat'><option value=''>Select one</option>"; foreach ($dbo->query($quer) as $noticia) { echo "<option value='$noticia[subcategory]'>$noticia[subcategory]</option>"; } echo "</select>"; ////////////////// This will end the second drop down list /////////// //// Add your other form fields as needed here///// echo "<input type=submit value=Submit>"; echo "</form>"; ?> <br><br> <a href=dd.php>Reset and start again</a> <br><br> <center><a href='http://www.plus2net.com' rel="nofollow">PHP SQL HTML free tutorials and scripts</a></center> </body>
  9. shams

    Two dropdown menu in php?

    Thanks to all, i got the multiple drop down list box code from the plus2net.com, arranged my html pages in a mysql database in table category with columns category id and category name and second table subcategory with category id and their html pages, i select the category from first drop down menu and then it's html page from second drop down menu it prints the category id and it's html page name: Value of $cat = 2 Value of $subcat = 002_001.html how to pass this value to other php code to open this html page?
  10. shams

    Two dropdown menu in php?

    I didn't created any database for it, guide me to a link i can do, or if can be possible without any database?
  11. My site will have nearly 2000 html pages, they are grouped in 114 categories each category have many pages, i want to have two dropdown menu in first menu select the category and in the second menu the page to open, i got this code from thesitewizard.com it is working just for one dropdown menu: <form action="chgoto.php" method="get"> <select name="url" onchange="menu_goto(this.form)"> <option value="001_001.html">page 1</option> <option value="001_003.html">page 3</option> <option value="001_005.html">page 5</option> </select> <input type="submit" value="Go!" /> this is chgoto.php: <?php $baseurl = "/" ; $url = $_REQUEST['url'] ; header( "Location: " . $baseurl . $url ); exit ; ?>
  12. I use the ar-php library with still gd library to wirte the text on image, some arabic letters has more chars in the above and below, this text lines are too short on image, but other letters without extra chars are in the normal length, this is the code <?php require_once __DIR__.'/../vendor/autoload.php'; use GDText\Box; use GDText\Color; require('../I18N/Arabic.php'); $Arabic = new I18N_Arabic('Glyphs'); $box = new Box($im); $box->setFontFace(__DIR__.'/../fonts/BahijRegular.ttf'); $box->setFontSize(20); $box->setFontColor(new Color(0 , 0, 0)); // $box->setTextShadow(new Color(0, 0, 0, 50), 0, -2); $box->setBox(5, 20, 580, 300); $box->setTextAlign('right', 'top'); $im = imagecreatefromjpeg(__DIR__.'/../img/img.jpeg'); $text = file_get_contents('/home/user/message'); $text = $Arabic->utf8Glyphs($text); $box->draw($text); header("Content-type: image/jpeg"); imagejpeg($im); This is the output of this code: http://ibb.co/ea1sZ5 The first five lines are too short while others text is normal length, is it possible to make these lines longer?
  13. I am sorry for if i am wrong for my post, we appreciate all php developers as well cys0der for farsi class, here is the original text in i wrote in gedit ;حدیث مسلم :کتاب البروالصله والاداب: رقم الحدیث ۲۵۷۷: ازابوذر رضی الله عنه روایت است که نبی صلی الله وعلیه وصلم از قول الله سبحانه وتعالی چنین فرمود: ای بندگانم ! من ظلم را بر خود حرام کردم ومیان شما حرام گردانیده ام پس بر هم دیگر ظلم مکنید. ای بندگان ! همه شما گمراهید مگر کسی که من هدایتش کنم پس طلب هدایتم کنید تا هدایتتان کنم. ای بندگانم ! همه شما گشنه اید مگر کسی که من طعامش دهم پس از من طلب طعام کنید تا شما را خوراک دهم. ای بندگانم ! همه شما بدون پوششید مگر کسی که من پوشش دهم از من پوشش بخواهید تا شما را بپوشانم. ای بندگانم! شما شب و روز گناه می کنید ومنم که تمام گناهان را می بخشم پس از من طلب بخشش کنید تا شما را ببخشم. ای بندگانم ! شما توان زیان‌رساندن به من را ندارید، تا زیانم رسانید و توان سودرساندن به من را نیز ندارید، تا به من سودی رسانید. i use the above code with the: $text = file_get_contents('/home/user/message'); This is the image ouput: https://ibb.co/fd1QWk The above original text is written in 8 lines but on image it is written in one line and the other problem is the text is written in bizarre order the last line is in the beginning. I am writing each line once and then the other one to write the all above text.
  14. Thanks for all finally i realized that the class FarsiGD() didn't support to write the text in multiple lines, i removed the line: $text = file_get_contents('/home/user/message'); and inserted this code: $lines = file("/home/user/message"); foreach($lines as $line) $text = ($line . "\n"); but the code writes only the last line on the image and ignoring the other previous lines.
  15. Sorry for inconvenience, I want to write text on image this is the original code, it writes the whole text in one line, i want to write the text in new lines as it's original text: <?php require __DIR__.'/../vendor/autoload.php'; use GDText\Box; use GDText\Color; include('../src/FarsiGD.php'); $im = imagecreatetruecolor(500, 500); $backgroundColor = imagecolorallocate($im, 0, 18, 64); imagefill($im, 0, 0, $backgroundColor); $box = new Box($im); $box->setFontFace(__DIR__.'/fonts/BahijRegular.ttf'); $box->setFontColor(new Color(255, 75, 140)); $box->setTextShadow(new Color(0, 0, 0, 50), 2, 2); $box->setFontSize(23); $box->setLineHeight(1.5); $box->enableDebug(); $box->setBox(20, 20, 460, 460); $box->setTextAlign('right', 'top'); $gd = new FarsiGD(); $text = file_get_contents('/home/user/message'); $text = $gd->persianText($text, 'fa', 'normal'); $box->draw($text); header("Content-type: image/png;"); imagepng($im, null, 9, PNG_ALL_FILTERS); The file_get_contents() output the whole text in one line how to output in new lines within this code?

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.