Jump to content

mysql php


anf.etienne

Recommended Posts

I have a php form with that has four radio buttons. Depending on which radio button is submitted i want php to get information from my db.

 

the ID of the buttons are 1,2,3 and 4.....they correspond to row 1,2,3 and 4 of my db how do i retieve rows 1 if button 1 is selected? Ive been through a lot of websites to find out but they dont explain retrieving a specific row

Link to comment
Share on other sites

At the end of your query, add:

 

LIMIT X, 1

 

Change X to the number of the database row you want. How this works is that it starts at row X, and gives you 1 row. And remember, X will start at 0, so if you want the first row, you will set X=0, and if you want the second row, you will set X=1 etc.

Link to comment
Share on other sites

no i don't want to create anything as complicated as that yet. I just want to create a php form where a user selects either options 1, 2, 3 or 4 and when they click continue the php will retrieve the either row with the corresponding ID.

 

I've not done php & mysql for a loooong time and went more into graphic design and ive forgotten a lot of things lol so now im back to being a php swl newbie......the joy.

 

thanks in advance for anyone that recaps me on this lol

Link to comment
Share on other sites

hi! try this...Hope its work for you.

 

<?php

define("HOST", "localhost");

// Database user

define("DBUSER", "root");

// Database password

define("PASS", "******");

// Database name

define("DB", "Database_Name"); //Database_Name

############## Make the mysql connection ###########

$conn = mysql_connect(HOST, DBUSER, PASS);

if (!$conn){

// the connection failed so quit the script

die('Could not connect !<br />Please contact the site\'s administrator.');

}

$db = mysql_select_db(DB);

if (!$db){

// cannot connect to the database so quit the script

die('Could not connect to database !<br />Please contact the site\'s administrator.');

}

?>

<form id="form1" name="form1" method="post" action="test.php">

<p>

  <label>

    <input type="radio" name="radio1" id="r1" value="1" <?=($_POST['radio1'])==1?'checked':''?> />1</label>

  <label>

    <input type="radio" name="radio1" id="r2" value="2" <?=($_POST['radio1'])==2?'checked':''?> />2</label>

  <label>

    <input type="radio" name="radio1" id="r3" value="3" <?=($_POST['radio1'])==3?'checked':''?> />3</label>

  <label>

    <input type="radio" name="radio1" id="r4" value="4" <?=($_POST['radio1'])==4?'checked':''?> />4</label>

  </p>

<p>

    <input type="submit" value="Get Row" />

    </p>

</form>

<?

if($_POST){

$sql = "select user_id,name,email from sys_user where user_id='".$_POST['radio1']."';";

$res = mysql_query($sql);

    while ($row = mysql_fetch_array($res)){

echo $row[0].' - '.$row[1].' - '.$row[2]."<br>";

}

mysql_free_result($res);

mysql_close();

}

?>

 

 

 

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.